<template>
	<view class="uni-navbar">
		<view :class="{ 'uni-navbar--fixed': fixed, 'uni-navbar--shadow': shadow, 'uni-navbar--border': border }" :style="{ 'background-color': backgroundColor }"
		 class="uni-navbar__content">
			<uni-status-bar v-if="statusBar" />
			<view :style="{ color: color,backgroundColor: backgroundColor }" class="uni-navbar__header ">
				<view class="uni-navbar__header-btns uni-navbar__header-btns-left uni-navbar__content_view">
					<view class="uni-navbar__content_view" @tap="onClickLeft" v-if="leftIcon.length">
						<uni-icons :color="color" :type="leftIcon" size="24" />
					</view>
					<view @tap="onClickSearch" style="margin-right: 10upx;vertical-align: middle;padding: 0 20upx;">
						<uni-icons color="#333333" :type="searchIcon" size="20" />
					</view>
					<view :class="{ 'uni-navbar-btn-icon-left': !leftIcon.length }" @tap="onClickLeft" class="uni-navbar-btn-text uni-navbar__content_view"
					 v-if="leftText.length">
						<text class="leftText" :style="{ color: color, fontSize: '14px' }">{{ leftText }}</text>
						<text style="color:#444444;font-size: 20upx;" v-if="serviceFinished">{{orderMsg}}</text>
					</view>
					<view v-if="title.length" class="title-wrapper">
						<text class="uni-nav-bar-text" :style="{color: color }">{{ title }}</text>
					</view>
					<slot name="left" />
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import uniStatusBar from "../uni-status-bar/uni-status-bar.vue";
	import uniIcons from "../uni-icons/uni-icons.vue";

	export default {
		name: "UniNavBar",
		components: {
			uniStatusBar,
			uniIcons
		},
		props: {
			title: {
				type: String,
				default: ""
			},
			leftText: {
				type: String,
				default: ""
			},
			orderMsg: {
				type: String,
				default: ""
			},
			rightText: {
				type: String,
				default: ""
			},
			leftIcon: {
				type: String,
				default: ""
			},
			searchIcon: {
				type: String,
				default: ""
			},
			rightIcon: {
				type: String,
				default: ""
			},
			fixed: {
				type: [Boolean, String],
				default: false
			},
			color: {
				type: String,
				default: "#000000"
			},
			serviceFinished: {
				type: Boolean,
				default: false
			},
			backgroundColor: {
				type: String,
				default: "#FFFFFF"
			},
			statusBar: {
				type: [Boolean, String],
				default: false
			},
			shadow: {
				type: [String, Boolean],
				default: false
			},
			border: {
				type: [String, Boolean],
				default: true
			}
		},
		mounted() {
			if (uni.report && this.title !== '') {
				uni.report('title', this.title)
			}
		},
		methods: {
			onClickLeft() {
				this.$emit("clickLeft");
			},
			onClickRight() {
				this.$emit("clickRight");
			},
			onClickSearch() {
				this.$emit("onClickSearch");
			}
		}
	};
</script>

<style lang="scss" scoped>
	$nav-height: 44px;

	.uni-navbar__header {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		width: 750rpx;
		height: $nav-height;
		line-height: $nav-height;
		font-size: 16px;
		// background-color: #ffffff;
		display: flex;
		align-items: center;
	}

	.uni-navbar__content_view {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		align-items: center;

		flex-direction: row;

		// background-color: #FFFFFF;
	}

	.uni-navbar-btn-text {
		display: flex;
		flex-direction: column;
		height: $nav-height;
		align-items: flex-start;
		justify-content: center;
	}

	.uni-navbar__content_view text {
		max-width: 440rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		line-height: normal;
	}

	.leftText {
		font-size: 34upx !important;
		font-weight: 500;
	}

	.title-wrapper {
		display: inline;
	}

	.uni-nav-bar-text {
		font-size: 20upx !important;
		color: #B6890E !important;
		background: rgba(255, 237, 187, .85) !important;
		border-radius: 8px !important;
		margin-left: 18upx !important;
		// display: inline-block;
		padding: 2upx 14upx !important;

	}

	.uni-nav-bar-right-text {
		font-size: $uni-font-size-base;
	}

	.uni-navbar {
		width: 750rpx;
	}

	.uni-navbar__content {
		position: relative;
		width: 750rpx;
		background-color: $uni-bg-color;
		overflow: hidden;
	}





	.uni-navbar__header-btns {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-wrap: nowrap;
		// width: 120rpx;
		padding: 0 6px;
		justify-content: center;
		align-items: center;
	}

	.uni-navbar__header-btns-left {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		// width: 150rpx;
		justify-content: flex-start;
	}

	.uni-navbar__header-btns-right {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		// width: 150rpx;
		padding-right: 30rpx;
		justify-content: flex-end;
	}

	.uni-navbar__header-container {
		flex: 1;
	}

	.uni-navbar__header-container-inner {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex: 1;
		align-items: center;
		justify-content: center;
		font-size: $uni-font-size-base;
	}


	.uni-navbar__placeholder-view {
		height: $nav-height;
	}

	.uni-navbar--fixed {
		position: fixed;
		z-index: 998;
		top: 0;
	}

	.uni-navbar--shadow {
		/* #ifndef APP-NVUE */
		box-shadow: 0 1px 6px #ccc;
		/* #endif */
	}

	.uni-navbar--border {
		// border-bottom-width: 1rpx;
		// border-bottom-style: solid;
		// border-bottom-color: $uni-border-color;
	}
</style>
